<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <title>达人文章</title>
    <style>
        #content{
            padding: 0 10px;
        }
        #langTitle{
            margin: 10px;
        }
        #content img{
            width: 100%;
        }
        .am-g{
          width: 100% !important;
        }
        .phone-title{
          font-size: 16px !important;
        }
        .commodity-price {
            border-right: 0 !important;
            overflow: hidden;
        }
        .commodity-price span:nth-child(1) {
          font-size: 16px !important;
          float:left;
        }
        .commodity-price span:nth-child(2) {
          font-size: 12px !important;
          float:left;
        }
        .commodity-tkmoney {
          display:none !important;
        }
        .commodity-tkrates {
          display:none !important;
        }
        .commodity-bottom span {
          font-size: 12px !important;
        }
        .single-info .single-tkmoney{
            display:none !important;
        }
        .single-info .single-tkrates{
            display:none !important;
        }
        .single-info .single-price{
            border:0 !important;
        }
        .single-info .single-price span:nth-child(1) {
          margin-right: 5px;
          line-height: 20px !important;
          font-size: 16px !important;
          float:left;
        }
        .single-info .single-price span:nth-child(2) {
          line-height: 20px !important;
          font-size: 16px !important;
          float:left;
        }
        .single-message .single-price{

        }
        #user{
            padding: 0 10px;
            line-height: 30px;
            overflow: hidden;
        }
        #userImg{
            width: 30px;
            height: 30px;
            overflow: hidden;
            border-radius: 50%;
            float: left;
        }
        #userName{
            font-size: 12px;
            margin-left: 5px;
            float: left;
        }
        #looks{
            font-size: 12px;
            float: right;
        }
        #shortTitle{
            margin: 15px;
        }
    </style>
</head>

<body>
    <div>
        <div id="topImg"></div>
        <div id="langTitle"></div>
        <div id="user">
            <div id="userImg"></div>
            <div id="userName"></div>
            <div id="looks"></div>
        </div>
        <div id="shortTitle"></div>
        <div id="content">
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
var aliBC
    apiready = function() {

        aliBC = api.require("aliBC");

        String.prototype.replaceAll = function (FindText, RepText) {
            regExp = new RegExp(FindText, "g");
            return this.replace(regExp, RepText);
        }
        var data = api.pageParam.data

        var urlTransform = window.urlTransformZGD(window.APIServerZGD.getProphetSayItem, {
            id:data
        })
        _Ajax(urlTransform, 'get', {}, 'json', function (ret) {
            if (ret.code === 1) {
                var _data = ret.data

                $api.html($api.byId('topImg'), '<img src = "'+_data.article_banner+'" />');
                $api.html($api.byId('langTitle'), _data.name );
                $api.html($api.byId('userImg'), '<img src = "'+_data.head_img +'_200x200.jpg " />');
                $api.html($api.byId('userName'), _data.talent_name);
                $api.html($api.byId('looks'), _data.readtimes);
                $api.html($api.byId('shortTitle'), '「 '+_data.shorttitle+' 」' );

                var article = _data.article.replaceAll("&lt;","<")
                var article2 = article.replaceAll("&gt;",">")
                var article3 = article2.replaceAll("&quot;",'"')

                $api.html($api.byId('content'), article3);
                var js_tobuy = $api.domAll('.js_tobuy')
                for (let i = 0; i < js_tobuy.length; i++) {
                    $api.addEvt($api.domAll('.js_tobuy')[i], 'click', function(e){
                        var buyData = {}
                        buyData.item_id = this.getAttribute('id').slice(6)

                        buy(buyData)
                    })
                }

            } else {
                console.log(JSON.stringify(ret))
            }
        });
    };

    function buy(item){
      var tjp = item.tjp||'t';
      if (tjp=='t') {
        aliBC.getUserInfo(function(ret,err){
            if(ret.status){
                _Ajax(window.APIServer.BindTb,'post',{values:ret},'json',function(ret){
                    if (ret.code==1) {
                        buy2(item);
                    }else{
                        _toast(ret.msg)
                        aliBC.logout(function(ret,err){});//清除授权
                    }
                })
            }else{
              //登录
              aliBC.showLogin(function(ret,err){
                  if(ret.status){
                      _Ajax(window.APIServer.BindTb,'post',{values:ret},'json',function(ret){
                          if (ret.code==1) {
                              buy2();
                          }else{
                              _toast(ret.msg)
                              aliBC.logout(function(ret,err){});//清除授权
                          }
                      })
                  }else{
                      _toast('授权失败');
                  }
              });
            }
        });
      }else{
        buy2(item);
      }
    }
    //购买
    function buy2(){
      var tjp = item.tjp||'t';
      api.openFrame({
          name: 'plane',
          url: 'widget://html/plane.html',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          },
          pageParam: {tjp:tjp},
          bounces: false,
      });
      _Ajax(window.APIServer.Buy,'post',{values:item},'json',function(ret){
          api.closeFrame({
              name: 'plane'
          });
          //必须后台转链，不然这里是打不开优惠券的，使用showPageByUrl,唤起手淘
          if (ret.code==1) {
             if (tjp=='t') {
                aliBC.showPageByUrl({
                  url:ret.data.return_url,
                  openType:'native',//'auto','h5','native'
                  pid:ret.data.pid,
                  taokeAppkey:ret.data.appkey,
                  adzoneId:ret.data.adzoneid,
                },function(ret,err){
                  //购买商品的回调

                });
              }else{
                var title = "京东";
                if (tjp=='p') {title = "拼多多"}
                openWeb({"title":title,"url":ret.data.return_url});
              }
          }else{
              _toast(ret.msg)
          }

      })

    }
</script>

</html>
